﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MathTest
{
    public partial class Getpaper : Form
    {
        public Getpaper()
        {
            InitializeComponent();

            dataGridView1.DataSource = GetItemTitle();
      
        }

        private DataTable GetItemTitle()
        {
            SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=ItemPool;Persist Security Info=True;User ID=sa;Password=123456");
            SqlCommand cmd = new SqlCommand();

            conn.Open();
            cmd.CommandText = "select * from ItemTitle";
            cmd.Connection = conn;

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();
            da.Fill(dt);
            da.Dispose();
            cmd.Dispose();
            conn.Close();
            return dt;
        }

        private void GetPaperBand()
        {
            if (rb1.Checked)
                dataGridView2.DataSource = GetPaper(5);
            else if (rb2.Checked)
                dataGridView2.DataSource = GetPaper(4);
            else if (rb3.Checked)
                dataGridView2.DataSource = GetPaper(3);
            else if (rb4.Checked)
                dataGridView2.DataSource = GetPaper(2);
        }


        private DataTable GetPaper(int paperCount)
        {
            SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=ItemPool;Persist Security Info=True;User ID=sa;Password=123456");
            SqlCommand cmd = new SqlCommand();

            conn.Open();
            cmd.CommandText = "delete from Paper exec Getpaper '" + paperCount + "'";
            cmd.Connection = conn;

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();
            da.Fill(dt);
            da.Dispose();
            cmd.Dispose();
            conn.Close();
            return dt;
        }

        private void rb1_CheckedChanged(object sender, EventArgs e)
        {
            GetPaperBand();
        }

        private void rb2_CheckedChanged(object sender, EventArgs e)
        {
            GetPaperBand();
        }

        private void rb3_CheckedChanged(object sender, EventArgs e)
        {
            GetPaperBand();
        }

        private void rb4_CheckedChanged(object sender, EventArgs e)
        {
            GetPaperBand();
        }



    }
}
